
var express = require('express')
var app = express()
var debug = require('debug')('my-application'); // debug模块
var bodyParser = require('body-parser');
//创建application/json解析
var jsonParser = bodyParser.json();

//创建application/x-www-form-urlencoded
var urlencodedParser = bodyParser.urlencoded({extended: false});

//POST /login 中获取URL编码的请求体
app.post('/setinfo', urlencodedParser, function(req, res){
    console.log(req.body);//获取的是params的参数
    let infoObj = {"code":"S_OK",data:{age:12,name:"evanlian"}}
    res.send(infoObj);
})

//POST /api/users 获取JSON编码的请求体
app.get('/getinfo', jsonParser, function(req,res){
  
  let obj = {
      "name":"evanlian",
      "job":"engineer222"
  }
  res.send(obj)
})


app.set('port', process.env.PORT || 4000); // 设定监听端口
 
//启动监听
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
